import { saveAs } from 'file-saver';
import { Workbook } from 'exceljs';
export const saveWorkBook = (workbook: Workbook, fileName: string) => {
  workbook.xlsx.writeBuffer().then((data) => {
    const blob = new Blob([data], { type: '' });
    saveAs(blob, fileName);
  });
};

const DEFAULT_COLUMN_WIDTH = 20;
export const generateHeaders = (columns: any[]) => {
  return columns?.map((col) => {
    const obj = {
      header: col.title,
      key: col.dataIndex,
      width: col.width / 5 || DEFAULT_COLUMN_WIDTH,
    };
    return obj;
  });
};
